package cn.edu.sgu.www.mhxysy.controller.wenshi;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.wenshi.WenshiAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.wenshi.WenshiAttribute;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.wenshi.WenshiAttributeService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "纹饰属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/wenshi_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class WenshiAttributeController {

	private final WenshiAttributeService wenshiAttributeService;

	@Autowired
	public WenshiAttributeController(WenshiAttributeService wenshiAttributeService) {
		this.wenshiAttributeService = wenshiAttributeService;
	}

	@ApiOperation("添加纹饰属性")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated WenshiAttributeDTO wenshiAttributeDTO) {
		wenshiAttributeService.insert(wenshiAttributeDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除纹饰属性")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(
			@ApiParam(name = "id", value = "纹饰属性ID", required = true)
			@NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
		wenshiAttributeService.deleteById(id);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过ID修改纹饰属性信息")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated WenshiAttributeDTO wenshiAttributeDTO) {
		wenshiAttributeService.updateById(wenshiAttributeDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过坐骑ID查询纹饰属性名称列表")
	@RequestMapping(value = "/selectByZuoqiId", method = RequestMethod.GET)
	public JsonResult<List<String>> selectByZuoqiId(
			@ApiParam(name = "zuoqiId", value = "坐骑ID", required = true)
			@NotBlank(message = CustomMessages.ZUOQI_ID_NOT_NULL) String zuoqiId) {
		List<String> list = wenshiAttributeService.selectByZuoqiId(zuoqiId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过纹饰ID查询纹饰属性名称列表")
	@RequestMapping(value = "/selectAttributes", method = RequestMethod.GET)
	public JsonResult<List<String>> selectAttributes(
			@ApiParam(name = "wenshiId", value = "纹饰ID", required = true)
			@NotBlank(message = CustomMessages.WENSHI_ID_NOT_NULL) String wenshiId) {
		List<String> list = wenshiAttributeService.selectAttributes(wenshiId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过纹饰ID查询纹饰属性列表")
	@RequestMapping(value = "/selectByWenshiId", method = RequestMethod.GET)
	public JsonResult<List<WenshiAttribute>> selectByWenshiId(
			@ApiParam(name = "wenshiId", value = "纹饰ID", required = false)
			@RequestParam(required = false) String wenshiId) {
		List<WenshiAttribute> list = wenshiAttributeService.selectByWenshiId(wenshiId);

		return JsonResult.success(null, list);
	}

}